package ${package.Controller};

import tbs.imt.data.model.vo.${table.entityPath}.${entity}ListVo;
import tbs.imt.data.model.vo.${table.entityPath}.${entity}DetailVo;
import tbs.imt.data.model.po.${table.entityPath}.${entity}CreatePo;
import tbs.imt.data.model.po.${table.entityPath}.${entity}UpdatePo;
import tbs.imt.data.model.po.${table.entityPath}.${entity}QueryPo;
import tbs.imt.data.model.po.${table.entityPath}.${entity}CreateBatchPo;
import tbs.imt.data.model.po.${table.entityPath}.${entity}UpdateBatchPo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import ${package.Service}.*;
import ${package.Entity}.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import javax.validation.Valid;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Slf4j
@Validated
@Api(tags = "${table.comment!}API")
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>
    @Autowired
	private ${table.serviceName} ${table.entityPath}Service;


    @ApiOperation("分页")
    @GetMapping("/page${entity}")
    public IPage<${entity}ListVo> page${entity}(${entity}QueryPo po) {
        return ${table.entityPath}Service.page${entity}(po);
    }


    @ApiOperation("查询")
    @GetMapping("/{guid}")
    public ${entity}DetailVo detail(@PathVariable("guid") String guid){
        return  ${table.entityPath}Service.detail(guid);
    }


    @ApiOperation("添加")
    @PostMapping
    public void create(@Valid @RequestBody ${entity}CreateBatchPo po){
        try {
            ${table.entityPath}Service.create(po);
        } catch (Exception e) {
            log.error("添加失败, e = {}", e.getMessage(), e);
            throw e;
        }
    }

    @ApiOperation("修改")
    @PutMapping
    public void update(@Valid @RequestBody ${entity}UpdateBatchPo po){
        try {
            ${table.entityPath}Service.update(po);
        } catch (Exception e) {
            log.error("修改失败, e = {}", e.getMessage(), e);
            throw e;
        }
    }

    @ApiOperation("删除")
    @DeleteMapping("/{guid}")
    public void delete(@PathVariable("guid") String guid){
        try {
            ${table.entityPath}Service.delete(guid);
        } catch (Exception e) {
            log.error("删除失败, e = {}", e.getMessage(), e);
            throw e;
        }
    }
}
</#if>
